#ifndef INTERPOLATION_H
#define INTERPOLATION_H
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <fstream>
#include <gsl/gsl_vector.h>
#include "tdma.h"
using namespace std;
#define DBG_INTERP 1


//class to perform interpolation of a cubic spline in 2-d i.e. y=f(x)
class Interpolation
{
   
   private:         
      int numPoints;
      //a is used as a(x-xi)^3 for cubic spline and as y=ax+b for linear
      gsl_vector* a;
      //b is used as b(x-xi)^2 for cubic spline and as y=ax+b for linear
      gsl_vector* b;
      gsl_vector* c;
      gsl_vector* d;
      
      //stores the coefficients in a vector for each segment of cubic spline
      vector < gsl_vector* > cSplineCoeffs;
      //stores the coefficients in a vector for each segment of line
      vector< gsl_vector* > lineCoeffs;

      //private methods
      void CubicSplineInterpolation1D( );
      int GetPosition( double xat );
      void LinearInterpolation( );
   
   public:
      Interpolation( );
      Interpolation( vector<double> x, vector<double> y );
      ~Interpolation( );
      
      void SetInputPoints1D( vector<double> xin, vector<double> yin );
      void SetInputPoints( map< int, vector< double > > inp, 
            gsl_matrix* out );
      //C Splines
      vector < gsl_vector* >  GetCubicSplineCoefficientVectors( );
      double EvaluateCubicSplineAt( double xat );
      double EvaluateCubicSplineAt( double xat, vector<double> xdata );
      
      //Linear Interpolation
      double EvaluateLinearAt( double xat );
      
      double EvaluateLinearAt( double xat, vector<double> xdata );
      //vector < gsl_vector* >  GetLinearCoefficientVectors( );
   protected:
      vector < double > x;
      vector < double > y;
      int GetPosition( double xat, vector<double> inpData );
};
#endif //INTERPOLATION_H


